<?php

$type_notification = get_input('type_notification');

if($type_notification == 'comment') {	
	
	$ratingid_receiver = get_input('ratingid_receiver');
	$name_sender = get_input('name_sender');
		
	$rating = get_entity($ratingid_receiver);
	$guid_receiver = $rating->getObjectOwnerGUID();
	
	$get_device_token_sql = "SELECT device_token FROM users_device_info WHERE userid = $guid_receiver";
	$results = get_data($get_device_token_sql);
	
	foreach($results as $result) {
		$deviceToken = $result->device_token;
	}
	// Put your alert message here:
	$message = $name_sender . ' commented on your rating.';
}

if($type_notification == 'request_friend') {
	$guid_receiver = get_input('guid_receiver');
	$name_sender = get_input('name_sender');
	$contact_id = get_input('contact_id');
	
	$get_device_token_sql = "SELECT device_token FROM users_device_info WHERE userid = $guid_receiver";
	$results = get_data($get_device_token_sql);
	
	foreach($results as $result) {
		$deviceToken = $result->device_token;
	}
	// Put your alert message here:
	$message = $name_sender . ' wants to add you as a friend.';
}

if($type_notification == 'accept_friend') {
	$guid_receiver = get_input('guid_receiver');
	$name_sender = get_input('name_sender');
	
	$get_device_token_sql = "SELECT device_token FROM users_device_info WHERE userid = $guid_receiver";
	$results = get_data($get_device_token_sql);
	
	foreach($results as $result) {
		$deviceToken = $result->device_token;
	}
	// Put your alert message here:
	$message = $name_sender . ' accepted you as a friend.';
}

if($type_notification == 'deny_friend') {
	$guid_receiver = get_input('guid_receiver');
	$name_sender = get_input('name_sender');
	
	$get_device_token_sql = "SELECT device_token FROM users_device_info WHERE userid = $guid_receiver";
	$results = get_data($get_device_token_sql);
	
	foreach($results as $result) {
		$deviceToken = $result->device_token;
	}
	// Put your alert message here:
	$message = $name_sender . ' denies your friend request.';
}

if($type_notification == 'cancel_friend') {
	$guid_receiver = get_input('guid_receiver');
	$name_sender = get_input('name_sender');
	
	$get_device_token_sql = "SELECT device_token FROM users_device_info WHERE userid = $guid_receiver";
	$results = get_data($get_device_token_sql);
	
	foreach($results as $result) {
		$deviceToken = $result->device_token;
	}
	// Put your alert message here:
	$message = $name_sender . ' cancel requesting you as a friend.';
}

if($type_notification == 'remove_friend') {
	$guid_receiver = get_input('guid_receiver');
	$name_sender = get_input('name_sender');
	
	$get_device_token_sql = "SELECT device_token FROM users_device_info WHERE userid = $guid_receiver";
	$results = get_data($get_device_token_sql);
	
	foreach($results as $result) {
		$deviceToken = $result->device_token;
	}
	// Put your alert message here:
	$message = $name_sender . ' removed you as a friend.';
}

header("Location: http://184.106.69.13/elgg/pushdemo/simplepush.php?device_token=$deviceToken&message=$message&contact_id=$contact_id&type_notification=$type_notification");